/**
 * 
 */
package com.chinamobile.maps.dao.impl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.chinamobile.maps.dao.IRegionsDAO;
import com.chinamobile.maps.orm.Channelnetworks;
import com.chinamobile.maps.orm.Regions;

/**
 * @author FrankWong
 *
 */
public class RegionsDAOImpl extends HibernateDaoSupport implements IRegionsDAO {

	/* (non-Javadoc)
	 * @see com.chinamobile.maps.dao.IRegionsDAO#addRegions(com.chinamobile.maps.orm.Regions)
	 */
	@Override
	public void addRegions(Regions regions) {
		this.getHibernateTemplate().save(regions);
	}

	/* (non-Javadoc)
	 * @see com.chinamobile.maps.dao.IRegionsDAO#delRegions(com.chinamobile.maps.orm.Regions)
	 */
	@Override
	public void delRegions(Regions regions) {
		this.getHibernateTemplate().delete(regions);
	}

	/* (non-Javadoc)
	 * @see com.chinamobile.maps.dao.IRegionsDAO#delRegions(int)
	 */
	@Override
	public void delRegions(int id) {
		this.getHibernateTemplate().delete(getRegionsById(id));
	}

	/* (non-Javadoc)
	 * @see com.chinamobile.maps.dao.IRegionsDAO#updateRegions(com.chinamobile.maps.orm.Regions)
	 */
	@Override
	public void updateRegions(Regions regions) {
		this.getHibernateTemplate().update(regions);
	}

	/* (non-Javadoc)
	 * @see com.chinamobile.maps.dao.IRegionsDAO#getRegions()
	 */
	@Override
	public List<Regions> getRegions() {
		List list = this.getHibernateTemplate().find("from Regions");
		if (list != null && list.size() > 0) {
			return list;
		}
		return null;
	}

	/* (non-Javadoc)
	 * @see com.chinamobile.maps.dao.IRegionsDAO#getRegionsById(int)
	 */
	@Override
	public Regions getRegionsById(int id) {
		List list = this.getHibernateTemplate().find("from Regions as regions where regions.id=?",
				new Object[] { id });

		if (list != null && list.size() > 0) {
			return (Regions) list.get(0);
		}
		return null;
	}

	/* (non-Javadoc)
	 * @see com.chinamobile.maps.dao.IRegionsDAO#getObjects(java.lang.String)
	 */
	@Override
	public List<Regions> getObjects(String hsql) {
		List list = this.getHibernateTemplate().find(hsql);
		if (list != null && list.size() > 0) {
			return list;
		}
		return null;
	}

	@Override
	public Regions getRegionsByName(String name) {
		List list = this.getHibernateTemplate().find("from Regions as regions where regions.name=?",
				new Object[] { name});

		if (list != null && list.size() > 0) {
			return (Regions) list.get(0);
		}
		return null;
	}

}
